<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.menggudf.model.SystemAdminModel" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	SystemAdminModel m=(SystemAdminModel)request.getSession().getAttribute("SystemAdminModel");
	String name = request.getSession().getAttribute("SystemAdminModel")==null ? "":m.getAdminName();
	String adminCode = request.getSession().getAttribute("SystemAdminModel")==null ? "":m.getAdminCode();
%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 
<style>
	body{
		background-color:#052550;
	}
	.sidebar{
		background-color:#052550;
		color:#adb3bb;
	}
	.sidebar ul li{
		border-bottom:none;
	}
	.sidebar .nav > li > a:hover, .sidebar .nav > li > a:focus{
		background-color:#2b343e;
		color:#fff;
	}
	.sidebar a{
		color:#a9b1bc;
	}
	.sidebar ul li a.active{
		background-color:#2b343e;
		color:#fff;
	}
	.sidebar li > a >.fa {
		padding-right: 5px;
	}
</style>
<div class="navbar-default sidebar" role="navigation">
	<div class="sidebar-nav navbar-collapse">
		<ul class="nav" id="side-menu">
           <li>
			 <div style="height: 5px;"></div>
		   </li> 
		</ul>
	</div>
</div>

<script type="text/javascript">
var adminCode  = '<%=adminCode %>';
	var user_left_permission;
var _menusjson = {
	"menus" : [{
		"menuid": "1",
		"icon": "fa fa-user",
		"permCode":"USER_MODULE",
		"menuname": "用户管理",
		"menus":[{
			"menuid" : "10",
			"menuname" : "用户列表",
			"permCode":"USER_LIST",
			"icon" : "icon-database",
			"url": "jsp/user/userlist.jsp"
		},
		{
			"menuid" : "12",
			"menuname" : "邀请码列表",
			"permCode":"INVITATION_LIST",
			"icon" : "icon-database",
			"url": "jsp/user/invitationlist.jsp"
		},
		{
			"menuid" : "11",
			"menuname" : "管理员列表",
			"permCode":"ADMIN_LIST",
			"icon" : "icon-database",
			"url": "jsp/user/sysadmin.jsp"
		}]
		},
		{
		"menuid": "2",
		"icon": "fa fa-medkit",
		"permCode":"ILL_MODULE",
		"menuname": "病历管理",
		"menus":[

			/*{
        "menuid" : "20",
        "menuname" : "疾病列表",
        "permCode":"ILL_LIST",
        "icon" : "icon-database",
        "url": "jsp/illness/illness.jsp"
    },
    {
        "menuid" : "21",
        "menuname" : "症状列表",
        "permCode":"SYMP_LIST",
        "icon" : "icon-database",
        "url": "jsp/illness/symptom.jsp"
    },
    {
        "menuid" : "22",
        "menuname" : "疾病导入",
        "permCode":"ILL_IMPORT",
        "icon" : "icon-database",
        "url": "jsp/illness/exportillness.jsp"
    } ,
    {
        "menuid" : "22",
        "menuname" : "人体模拟操作",
        "permCode":"",
        "icon" : "icon-database",
        "url": "jsp/illness/bodysimulation.jsp"
    } ,*/
			/*{
                "menuid" : "23",
                "menuname" : "部位列表",
                "permCode":"PART_LIST",
                "icon" : "icon-database",
                "url": "jsp/illness/partList.jsp"
            },
            {
                "menuid" : "24",
                "menuname" : "结果解读",
                "permCode":"RESULT_R",
                "icon" : "icon-database",
                "url": "jsp/illness/syscasehistoryList.jsp"
            },*/
		{
			"menuid" : "24",
			"menuname" : "病历列表",
			"permCode":"RESULT_R",
			"icon" : "icon-database",
			"url": "jsp/illness/medicalrecordList.jsp"
		}]
		},
				/*{
		"menuid": "3",
		"icon": "fa fa-suitcase",
		"permCode":"MEDICINE_MODULE",
		"menuname": "药品管理",
		"menus":[{
			"menuid" : "30",
			"menuname" : "药品列表",
			"permCode":"M_LIST",
			"icon" : "icon-database",
			"url": "jsp/illness/medicineList.jsp"
		},
		{
			"menuid" : "31",
			"menuname" : "检查药品列表",
			"permCode":"M_LIST",
			"icon" : "icon-database",
			"url": "jsp/illness/checkMedicineList.jsp"
		}]
		},*/
		{
		"menuid": "4",
		"icon": "fa fa-file-text-o",
		"permCode":"FILE_MODULE",
		"menuname": "文章管理",
		"menus":[{
			"menuid" : "40",
			"menuname" : "文章链接",
			"permCode":"F_LIST",
			"icon" : "icon-database",
			"url": "jsp/aricle/linkAricleList.jsp"
		}]
		}
	]
}; 
function InitLeftMenu() {
	$.ajax({
		url : './adminPerssion/getAdminPerssionCode',
		type : 'POST',
		data : {
			'adminCode' : adminCode
		},
		dataType : 'json',
		success : function(data) {
            user_left_permission = data
            $.each(_menusjson.menus, function(i, n) {
				var isHasPerm;
				if(n.permCode){
					isHasPerm = data[n.permCode];
				}else{
					isHasPerm = true;
				}
				var icond = "";
				if(n.icon){
					icond = n.icon;
				}
				if(isHasPerm){				
					var liNav = 
					$("<li><a id ='menu_"+n.menuid+"' href=\"\"><i class=\""+icond+"\"></i>"+n.menuname+"</a></li>");
					if(n.menus && n.menus.length > 0){
						liNav.find("#menu_"+n.menuid).append("<span class=\"fa arrow\"></span>");
						var ul2 = $("<ul class=\"nav nav-second-level\"></ul>");
						$.each(n.menus, function(j, o) {
							var isH;
							if(o.permCode){
							isH = data[o.permCode];
							}else{
								isH = true;
							}
							if(isH){
														    var url2 = o.url ? o.url :"";
							var liNav2 = $("<li><a id ='"+o.menuid+"' href=\""+url2+"\">"+o.menuname+"</a></li>");
							ul2.append(liNav2);
							if (o.child && o.child.length > 0 ) {
								var ul3 = $("<ul class=\"nav nav-third-level\"></ul>");
								$.each(o.child, function(k, p) {
									var isHP;
									if(p.permCode){
									isHP = data[p.permCode];
									}else{
										isHP = true;
									}
									if(isHP){
										var url3 = p.url ? p.url :"";
										var liNav3 = $("<li><a id ='"+p.menuid+"' href=\""+url3+"\">"+p.menuname+"</a></li>");
										ul3.append(liNav3);
									}
								});
								liNav2.append(ul3);
							}
						}
							});
					}

					liNav.append(ul2);
				}
				$("#side-menu").append(liNav);
				var url = window.location;
			    var element = $('ul.nav a').filter(function() {
			    	if($(this).attr('href') == "" || $(this).attr('href') == "#") {
			    		return false;
			    	}
			        return this.href == url || url.href.indexOf(this.href) == 0;
			    }).addClass('active').parent().parent().addClass('in').parent();
			    if (element.is('li')) {
			        element.addClass('active');
			    }
				
			});
			$('#side-menu').metisMenu();
			}
	});
}
$(function() {
    InitLeftMenu();
});
</script>